import QtQuick 2.12
import QtQuick.Controls 2.12

// ListView 右键弹出菜单

Item {
    id: root
    anchors.fill: parent
    property alias popupVisible: popup.visible
    property alias contentItem: popup.contentItem
    property color barColor: "white"
    property alias backgroundItem: background
    property real backgroundWidth: 200
    property real backgroundHeight: 160
    property color borderColor:  barColor
    property real borderWidth: 0


    //
    property  double startX
    property double  startY


    property real verticalOffset: 20
    //矩形旋转45度，一半被toolTip遮住(重合)，另一半三角形和ToolTip组成一个带箭头的ToolTip
    //    Rectangle {
    //        id: bar
    //        visible: popup.visible
    //        rotation: 45
    //        width: 16
    //        height: 16
    //        color: barColor
    //        //水平居中
    //        anchors.horizontalCenter: parent.horizontalCenter
    //        //垂直方向上，由ToolTip的y值，决定位置
    //        anchors.verticalCenter: parent.bottom
    //        anchors.verticalCenterOffset: verticalOffset
    //    }

    Popup {
        id: popup
        width: backgroundWidth
        height: backgroundHeight
        background: Rectangle {
            id: background
            color: barColor
            radius: 8
            border.color:borderColor
            border.width: borderWidth
        }
    }
    function show() {
        popup.x = startX
        popup.y = startY
        popupVisible = true
    }
    function hide() {
        popupVisible = false
    }
}
